/*
 * @Author: Nico 339477680@qq.com
 * @Date: 2023-04-04 17:35:40
 * @LastEditors: Nico 339477680@qq.com
 * @LastEditTime: 2023-04-22 17:38:33
 * @FilePath: \vue-manage-system-4.2.0\src\utils\request.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import axios from 'axios';

const service = axios.create({
    // process.env.NODE_ENV === 'development' 来判断是否开发环境   
    // baseURL: '/',
    timeout: 5000
});
// axios.defaults.baseURL ='/api';

switch (process.env.NODE_ENV) {
    case 'development':
      // 本地
      axios.defaults .baseURL = '/api'
  
      break
    case 'production':
    // 生产环境
    //   axios.defaults .baseURL = 'http://gongxiangtaiqiu.axa2.com'
    axios.defaults .baseURL = '/api'
      break
  }
service.interceptors.request.use(
    config => {
        return config;
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

service.interceptors.response.use(
    response => {
        if (response.status === 200) {
            return response.data;
        } else {
            Promise.reject();
        }
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

export default service;
